from langchain_core.tools import tool
from langchain_core.messages import AIMessage
from langgraph.prebuilt import ToolNode

@tool
def get_weather(location:str):
    """用户接收当前城市"""
    if location.lower() in ['sf','san francisco']:
        return "It's 16 degress and foggy"
    else:
        return "It's not 32 degress"

@tool
def get_coolest_cities():
    """获取最冷城市名称"""
    return "哈尔滨"

#手动调用toolnode
tools = [get_weather, get_coolest_cities]
tool_node = ToolNode(tools)
message_with_single_tool_call = AIMessage(
    content='',
    tool_calls = [
        {
            "name":"get_weather",
            "args":{"location":"sf"},
            "id":"4343",
            "type":"tool_call"
        }
    ]
)
tool_node_output = tool_node.invoke({"messages":[message_with_single_tool_call]})
print(tool_node_output)